﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Grid.Extensions
{
    public class DataGridViewFontCell : DataGridViewTextBoxCell
    {
        public DataGridViewFontCell() : base()
        {
            //Style.Font = new Font("Arial", 10);
        }

        public override void InitializeEditingControl(int rowIndex, object 
            initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
        {
            // Set the value of the editing control to the current cell value.
            base.InitializeEditingControl(rowIndex, initialFormattedValue, 
                dataGridViewCellStyle);

            DataGridViewTextBoxEditingControl ctl =
                DataGridView.EditingControl as DataGridViewTextBoxEditingControl;
            ctl.ReadOnly = true;
            using (FontDialog fd = new FontDialog())
            {
                fd.Font = (Font)this.Value;
                if (fd.ShowDialog() == DialogResult.OK)
                    this.Value = fd.Font;
                ctl.Text = String.Format("{0}; {1}pt", fd.Font.FontFamily.Name, fd.Font.SizeInPoints);
                //Style.Font = fd.Font;
            }
        }

        public override Type EditType
        {
            get
            {
                // Return the type of the editing contol that CalendarCell uses.
                return typeof(DataGridViewTextBoxEditingControl);
            }
        }

        public override Type ValueType
        {
            get
            {
                // Return the type of the value that CalendarCell contains.
                return typeof(Font);
            }
        }

        public override object DefaultNewRowValue
        {
            get
            {
                return new Font("Arial", 10);
            }
        }

    }
}
